package test.stub.ul1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import services.Format;


public class TraitFormatStub {
	
	public static Format traitFormatStub(String ligne) {
		Format f = null;
		if(ligne.equals("500 A0")) {
			f = new Format("F1", "160" );
		}
		else if(ligne.equals("501 17 B4")) {
			f = new Format("F2", "23 180");
		}
		
		else if(ligne.equals("502 42EF")) {
			f = new Format("F3", "66 239");
		}
		else if(ligne.equals("503 C2F3")) {
			f = new Format("F4", "194 243");
		}
		return f;
	}
	
	public static BufferedReader traitFormatStub(BufferedReader fjdt) throws IOException {
		String ligneJdt;
		File file = new File("resultTraitFormatStubOut.txt");
        BufferedWriter bw = new BufferedWriter(new FileWriter(file, false));
		try {
			while ((ligneJdt = fjdt.readLine()) != null) {
				Format f = TraitFormatStub.traitFormatStub(ligneJdt);
				bw.write(f.getNumFormat() + " " + f.getValeur());
				bw.newLine();
			}
			bw.close();
		}catch(Exception e) {
			
		}
		BufferedReader fTraitFormat = null;
		try {
			String fichierTraitFormatStubOut = "resultTraitFormatStubOut.txt";
			fTraitFormat = new BufferedReader(new FileReader(new File(fichierTraitFormatStubOut)));
		} catch (FileNotFoundException e) {
			System.out.println(e.getMessage());
		}
		return fTraitFormat;
	}

}
